﻿#region Copyright (c) 2000-2008 Developer Express Inc.
/*
{*******************************************************************}
{                                                                   }
{       Developer Express .NET Component Library                    }
{       AgDataGrid                                 }
{                                                                   }
{       Copyright (c) 2000-2008 Developer Express Inc.              }
{       ALL RIGHTS RESERVED                                         }
{                                                                   }
{   The entire contents of this file is protected by U.S. and       }
{   International Copyright Laws. Unauthorized reproduction,        }
{   reverse-engineering, and distribution of all or any portion of  }
{   the code contained in this file is strictly prohibited and may  }
{   result in severe civil and criminal penalties and will be       }
{   prosecuted to the maximum extent possible under the law.        }
{                                                                   }
{   RESTRICTIONS                                                    }
{                                                                   }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES           }
{   ARE CONFIDENTIAL AND PROPRIETARY TRADE                          }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS   }
{   LICENSED TO DISTRIBUTE THE PRODUCT AND ALL ACCOMPANYING .NET    }
{   CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY.                 }
{                                                                   }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                      }
{                                                                   }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON       }
{   ADDITIONAL RESTRICTIONS.                                        }
{                                                                   }
{*******************************************************************}
*/
#endregion Copyright (c) 2000-2008 Developer Express Inc.

using System.Windows.Controls;
using System.Windows.Media;
using System.Windows;
using DevExpress.AgDataGrid.Internal;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Windows.Media.Animation;
using System.Diagnostics.CodeAnalysis;
using System;
using System.Windows.Controls.Primitives;
using System.Reflection.Emit;
using DevExpress.AgDataGrid.Data;
using System.Windows.Automation.Peers;
using DevExpress.AgDataGrid.UIAutomation;
namespace DevExpress.AgDataGrid {
	public interface IElementPerformLayout {
		void PerformVisualLayout();
		double HeightAfterAnimation { get; }
		Size Measure(Size availableSize);
		void BeforeRemove();
		void AfterAdd();
	}
	public class AgDataGridCellData {
		public object RowValue { get; set; }
		public object CellValue { get; set; }
	}
	public interface IAgDataGridRowOwner {
		PanelColumnElementsBuilderBase CreateElementsBuilder(AgDataGridRow row, Panel cellsPanel);
		AgDataGridCellData GetCellValue(int rowHandle, string columnName, ref AgDataGridCellData cachedCellValue);
		object GetPreviewValue(int rowHandle);
		bool IsPreviewRow(int handle);
		bool IsPreviewAnimationBlocked { get; }
		DataTemplate GetPreviewTemplate();
		int GetLevel(int rowHandle);
		bool IsFocused(int rowHandle);
		bool IsMouseOver(int rowHandle);
		bool IsRowExpanded(int rowHandle);
		void ChangeExpandState(int rowHandle);
		bool IsSelected(int rowHandle);
		void OnPreviewApplyTemplate();
		double DataPanelWidth { get; }
		AgDataGridColumn FocusedColumn { get; }
		bool ChangeOddRowsAppearance { get; }
		DataPreviewVisibility PreviewVisibility { get; set; }
		void RaisePreviewEvents(int newRow, int oldRow);
		void UpdateVerticalScrollBar();
		void ApplyCellStyle(AgDataGridCell cell);
		bool IsEditorShown { get; }
		object GetGroupDisplayText(int handle);
	}
	public enum AgDataGridRowState { Normal = 0, AlternativeNormal, MouseOver, Focused, Selected }
	public enum AgDataGridRowType { Data, Group }
	[TemplatePart(Name = StateNormalName, Type = typeof(Storyboard))]
	[TemplatePart(Name = StateMouseOverName, Type = typeof(Storyboard))]
	[TemplatePart(Name = StateFocusedName, Type = typeof(Storyboard))]
	[TemplatePart(Name = StateSelectedName, Type = typeof(Storyboard))]
	[TemplatePart(Name = RootElementName, Type = typeof(Panel))]
	public abstract class AgDataGridRowBase : ContentControl, IElementPerformLayout, IFrameworkElement {
		const string StateNormalName = "Normal";
		const string StateNormalAlternativeName = "NormalAlternative";
		const string StateMouseOverName = "MouseOver";
		const string StateFocusedName = "Focused";
		const string StateSelectedName = "Selected";
		const string RootElementName = "RootElement";
		static string[] stateNames = new string[] { 
			StateNormalName,
			StateNormalAlternativeName,
			StateMouseOverName,
			StateFocusedName,
			StateSelectedName
		};
		Panel rootElement;
		int handle;
		IAgDataGridRowOwner owner;
		AgDataGridRowState state;
		public AgDataGridRowBase(int index, IAgDataGridRowOwner owner) {
			DefaultStyleKey = typeof(AgDataGridRowBase);
			this.handle = index;
			this.owner = owner;
			this.state = AgDataGridRowState.Normal;
		}
		public abstract AgDataGridRowType RowType { get; }
		public AgDataGridRowState State { get { return CalcNewRowState(); } }
		public bool IsFocused { get { return Owner.IsFocused(Handle); } }
		public bool IsSelected { get { return Owner.IsSelected(Handle); } }
		public bool IsMouseOver { get { return Owner.IsMouseOver(Handle); } }
		public int Level { get { return Owner.GetLevel(Handle); } }
		public double LevelIndent { get { return Level * AgDataGrid.DefaultLevelIndent; } }
		public AgDataGridColumn FocusedColumn { get { return Owner.FocusedColumn; } }
		protected double GetCellIndent(AgDataGridColumn column) {
			return column.VisibleIndex == 0 ? LevelIndent : 0;
		}
		protected internal void CalcRowState() {
			AnimateRow();
		}
		AgDataGridRowState CalcNewRowState() {
			AgDataGridRowState newState = (Handle % 2 == 1 && Owner.ChangeOddRowsAppearance) ? AgDataGridRowState.AlternativeNormal : AgDataGridRowState.Normal;
			if (IsMouseOver) newState = AgDataGridRowState.MouseOver;
			if (IsSelected) newState = AgDataGridRowState.Selected;
			if (IsFocused) newState = AgDataGridRowState.Focused;
			return this.state = newState;
		}
		protected virtual void AnimateRow() {
			if (RootElement == null || Parent == null) return;
			VisualStateManager.GoToState(this, stateNames[(int)State], true);
			AnimateCells();
		}
		public virtual void AnimateCells() {
		}
		protected internal IAgDataGridRowOwner Owner { get { return owner; } }
		public int Handle {
			get { return handle; }
			set {
				if (handle == value) return;
				handle = value;
				OnHandleUpdate();
			}
		}
		protected virtual void OnHandleUpdate() {
			AnimateRow();
		}
		protected internal Panel RootElement { get { return rootElement; } }
		public override void OnApplyTemplate() {
			base.OnApplyTemplate();
			this.rootElement = GetRootElement();
		}
		protected virtual Panel GetRootElement() {
			return GetTemplateChild(RootElementName) as Panel;
		}
		protected override Size MeasureOverride(Size availableSize) {
			PerformLayout();
			Size result = base.MeasureOverride(availableSize);
			return new Size(result.Width, Math.Ceiling(result.Height));
		}
		protected virtual void PerformVisualLayout() {
			SetIndentWidth();
			CalcRowState();
		}
		protected virtual void PerformLayout() {
			SetIndentWidth();
		}
		protected virtual void InvalidateMeasureEx() {
		}
		protected virtual void OnAfterAdd() {
		}
		protected virtual void OnBeforeRemove() {
		}
		protected Size RootElementSize {
			get {
				return RootElement != null ? new Size(RootElement.Width, RootElement.Height) : new Size(0, AgDataGrid.DefaultRowHeight);
			}
		}
		protected virtual void SetIndentWidth() {
			Margin = new Thickness(LevelIndent, 0, 0, 0);
		}
		#region IElementPerformLayout Members
		void IElementPerformLayout.PerformVisualLayout() {
			PerformVisualLayout();
		}
		protected internal virtual double HeightAfterAnimation() {
			if (ActualHeight == 0) return DesiredSize.Height;
			return ActualHeight;
		}
		double IElementPerformLayout.HeightAfterAnimation { get { return HeightAfterAnimation(); } }
		Size IElementPerformLayout.Measure(Size availableSize) {
			return MeasureOverride(availableSize);
		}
		void IElementPerformLayout.BeforeRemove() {
			OnBeforeRemove();
		}
		void IElementPerformLayout.AfterAdd() {
			OnAfterAdd();
		}
		#endregion
		#region IFrameworkElement Members
		Size IFrameworkElement.Measure(Size availableSize) {
			return MeasureOverride(availableSize);
		}
		void IFrameworkElement.InvalidateMeasureEx() {
			InvalidateMeasureEx();
		}
		#endregion
		protected internal virtual void UpdateCellState(AgDataGridCell cell) { }
		protected override AutomationPeer OnCreateAutomationPeer() {
			return new AgDataGridRowAutomationPeer(this);
		}
	}
	[TemplatePart(Name = ElementCellsName, Type = typeof(Canvas))]
	[TemplatePart(Name = ElementPreviewName, Type = typeof(ContentControl))]
	[TemplatePart(Name = PreviewStoryName, Type = typeof(Storyboard))]
	[TemplatePart(Name = PreviewAnimationName, Type = typeof(DoubleAnimation))]
	public class AgDataGridRow : AgDataGridRowBase {
		public static readonly DependencyProperty ShowVerticalLinesProperty = DependencyProperty.Register("ShowVerticalLines", typeof(bool), typeof(AgDataGridRow), null);
		public static readonly DependencyProperty VerticalLinesBrushProperty = DependencyProperty.Register("VerticalLinesBrush", typeof(Brush), typeof(AgDataGridRow), null);
		public static readonly DependencyProperty VerticalLinesThicknessProperty = DependencyProperty.Register("VerticalLinesThickness", typeof(double), typeof(AgDataGridRow), null);
		const string ElementCellsName = "CellsPresenterElement";
		const string ElementPreviewName = "PreviewPresenterElement";
		const string RootElementName = "RootElement";
		const string PreviewStoryName = "Preview Story";
		const string PreviewAnimationName = "Preview Animation";
		Panel cellsPanel;
		Dictionary<AgDataGridColumn, AgDataGridCell> cells;
		ContentControl previewPanel;
		Storyboard previewStoryboard;
		DoubleAnimation previewAnimation;
		double lastActualWidth, lastActualHeight;
		bool isTemplateLoaded;
		public AgDataGridRow(int index, IAgDataGridRowOwner owner)
			: base(index, owner) {
			DefaultStyleKey = typeof(AgDataGridRow);
			this.cells = new Dictionary<AgDataGridColumn, AgDataGridCell>();
			this.LayoutUpdated += OnLayoutUpdate;
		}
		protected void OnLayoutUpdate(object sender, EventArgs e) {
			if (Owner == null || (ActualHeight == lastActualHeight && ActualWidth == lastActualWidth)) return;
			if (!IsPreviewRow || (IsPreviewRow && ActualHeight == GetPreviewDesiredHeight()))
				Owner.UpdateVerticalScrollBar();
			lastActualWidth = ActualWidth;
			lastActualHeight = ActualHeight;
		}
		public override AgDataGridRowType RowType { get { return AgDataGridRowType.Data; } }
		protected bool IsTemplateLoaded { get { return isTemplateLoaded; } }
		public AgDataGridCell GetCell(AgDataGridColumn column) {
			if (!Cells.ContainsKey(column)) return null;
			return Cells[column];
		}
		public bool IsPreviewRow {
			get {
				if (PreviewPanel == null) ApplyTemplate();
				return PreviewPanel != null && Owner.IsPreviewRow(Handle);
			}
		}
		public bool ShowVerticalLines { get { return (bool)GetValue(ShowVerticalLinesProperty); } set { SetValue(ShowVerticalLinesProperty, value); } }
		public Brush VerticalLinesBrush { get { return (Brush)GetValue(VerticalLinesBrushProperty); } set { SetValue(VerticalLinesBrushProperty, value); } }
		public double VerticalLinesThickness { get { return (double)GetValue(VerticalLinesThicknessProperty); } set { SetValue(VerticalLinesThicknessProperty, value); } }
		protected Panel CellsPanel { get { return cellsPanel; } }
		protected internal ContentControl PreviewPanel { get { return previewPanel; } }
		protected PanelColumnElementsBuilderBase CreateElementsBuilder() {
			if (Owner == null) return null;
			return Owner.CreateElementsBuilder(this, CellsPanel);
		}
		protected Storyboard PreviewStoryboard {
			get {
				if (previewStoryboard == null)
					previewStoryboard = (Storyboard)GetTemplateChild(PreviewStoryName);
				return previewStoryboard;
			}
		}
		internal protected DoubleAnimation PreviewAnimation {
			get {
				if (previewAnimation == null)
					previewAnimation = (DoubleAnimation)GetTemplateChild(PreviewAnimationName);
				return previewAnimation;
			}
		}
		protected bool CanAnimate { get { return PreviewStoryboard != null && PreviewAnimation != null && IsPreviewAnimated; } }
		protected internal Dictionary<AgDataGridColumn, AgDataGridCell> Cells { get { return cells; } }
		public AgDataGridCell FocusedCell {
			get {
				if (!IsFocused || FocusedColumn == null || !Cells.ContainsKey(FocusedColumn)) return null;
				return Cells[FocusedColumn];
			}
		}
		public override void OnApplyTemplate() {
			base.OnApplyTemplate();
			CreateCellsPanel();
			CreatePreviewPanel();
			if (IsPreviewRow) {
				PreviewPanel.ApplyTemplate();
				Owner.OnPreviewApplyTemplate();
			}
			isTemplateLoaded = true;
		}
		protected override void InvalidateMeasureEx() {
			if (CellsPanel != null) {
				CellsPanel.InvalidateMeasureEx();
			}
		}
		protected override Size MeasureOverride(Size availableSize) {
			Size res;
			if (CellsPanel != null) {
				base.MeasureOverride(availableSize);
				CellsPanel.MeasureEx(availableSize);
				PreviewPanel.MeasureEx(availableSize);
				res = new Size(CellsPanel.DesiredSize.Width, CellsPanel.DesiredSize.Height + PreviewPanel.DesiredSize.Height);
			} else {
				res = base.MeasureOverride(availableSize);
			}
			res.Height = Math.Ceiling(res.Height);
			return res;
		}
		protected virtual void CreateCellsPanel() {
			this.cellsPanel = GetCellsPanel();
			BuildCells();
		}
		protected virtual void CreatePreviewPanel() {
			this.previewPanel = GetPreviewPanel();
		}
		protected virtual void BuildCells() {
			if (CellsPanel == null) return;
			CreateElementsBuilder().BuildElements();
		}
		protected virtual internal void BuildPreview() {
			if (PreviewPanel == null) return;
			if (Owner.GetPreviewTemplate() != null && PreviewPanel.DataContext != Owner.GetPreviewValue(Handle)) {
				PreviewPanel.Content = Owner.GetPreviewTemplate().LoadContent();
				PreviewPanel.DataContext = Owner.GetPreviewValue(Handle);
			}
		}
		protected virtual internal FrameworkElement GetCellControl(AgDataGridColumn column) {
			if (!Cells.ContainsKey(column)) {
				Cells[column] = CreateCellControl(column);
			}
			return Cells[column];
		}
		protected internal AgDataGridColumn GetColumnByCell(AgDataGridCell cell) {
			foreach (AgDataGridColumn column in Cells.Keys) {
				if (Cells[column] == cell) return column;
			}
			return null;
		}
		protected override void AnimateRow() {
			base.AnimateRow();
			if (IsPreviewRow) {
				if (!Owner.IsPreviewAnimationBlocked)
					ShowPreview();
			} else HidePreview();
		}
		AgDataGridRowState oldState = AgDataGridRowState.Normal;
		AgDataGridColumn oldFocusedColumn = null;
		public override void AnimateCells() {
			if (CellsPanel == null) return;
			if (oldState == State && oldFocusedColumn == Owner.FocusedColumn) return;
			AgDataGridColumn focusedColumn = Owner.FocusedColumn;
			foreach (UIElement child in CellsPanel.Children) {
				AgDataGridCell cell = child as AgDataGridCell;
				if (cell == null) continue;
				UpdateCellState(cell);
			}
			oldState = State;
			oldFocusedColumn = focusedColumn;
		}
		protected virtual AgDataGridCellState GetCellState(bool isFocused, AgDataGridRowState rowState, bool isEditorShown) {
			if (rowState == AgDataGridRowState.Focused) {
				if (isFocused) {
					return isEditorShown ? AgDataGridCellState.Editing : AgDataGridCellState.Focused;
				}
				return AgDataGridCellState.FocusedRow;
			}
			return AgDataGridCellState.Normal;
		}
		protected internal override double HeightAfterAnimation() {
			if (CellsPanel == null) return 0;
			if (CellsPanel.ActualHeight == 0.0) return CellsPanel.DesiredSize.Height + PreviewSizeAfterAnimation;
			return CellsPanel.ActualHeight + PreviewSizeAfterAnimation;
		}
		double cachedDesiredHeight;
		protected virtual double GetPreviewDesiredHeight() {
			if (cachedDesiredHeight == 0) {
				double oldHeight = PreviewPanel.Height;
				PreviewPanel.Height = double.NaN;
				PreviewPanel.InvalidateMeasureEx();
				if (VisualTreeHelper.GetParent(PreviewPanel) != null)
					PreviewPanel.Measure(new Size(ActualWidth, double.PositiveInfinity));
				PreviewPanel.Height = oldHeight;
				cachedDesiredHeight = Math.Ceiling(PreviewPanel.DesiredSize.Height);
			}
			return cachedDesiredHeight;
		}
		protected virtual void ResetFocusedCellState(AgDataGridCellState state) {
			if (FocusedCell == null) return;
			FocusedCell.State = state;
		}
		protected override void OnBeforeRemove() {
			if (CanAnimate) {
				PreviewStoryboard.Stop();
				if (PreviewAnimation.To.HasValue)
					PreviewPanel.Height = PreviewAnimation.To.Value;
			}
			ResetFocusedCellState(AgDataGridCellState.Normal);
		}
		protected internal bool IsPreviewAnimated { get { return Owner.PreviewVisibility == DataPreviewVisibility.ForFocusedRow; } }
		protected override void OnAfterAdd() {
			if (FocusedCell != null) {
				UpdateCellState(FocusedCell);
			}
			if (CanAnimate && !IsPreviewRow && PreviewPanel.Height > 0) PreviewPanel.Height = 0;
			if (!IsPreviewAnimated) ShowPreviewWithNoAnimation();
		}
		protected internal virtual void ShowPreview() {
			if (!CanAnimate || PreviewAnimation.To > 0) return;
			BuildPreview();
			PreviewAnimation.To = GetPreviewDesiredHeight();
			if (PreviewPanel.Height != PreviewAnimation.To) {
				if (double.IsNaN(PreviewPanel.Height)) PreviewPanel.Height = 0;
				Owner.RaisePreviewEvents(Handle, DataController.InvalidRow);
				PreviewStoryboard.Begin();
			}
		}
		public void ShowPreviewWithNoAnimation() {
			TogglePreviewWithNoAnimation();
		}
		public void TogglePreviewWithNoAnimation() {
			if (IsPreviewRow) {
				BuildPreview();
				Owner.RaisePreviewEvents(Handle, DataController.InvalidRow);
				PreviewPanel.Height = GetPreviewDesiredHeight();
			} else {
				if (PreviewPanel != null) {
					Owner.RaisePreviewEvents(DataController.InvalidRow, Handle);
					PreviewPanel.Height = 0;
				}
			}
		}
		protected internal virtual double PreviewSizeAfterAnimation {
			get {
				if (!IsPreviewRow || !IsTemplateLoaded) return 0;
				return GetPreviewDesiredHeight();
			}
		}
		protected internal virtual void HidePreview() {
			if (!CanAnimate) return;
			PreviewAnimation.To = 0;
			BuildPreview();
			if (PreviewPanel.Height != PreviewAnimation.To) {
				Owner.RaisePreviewEvents(DataController.InvalidRow, Handle);
				PreviewStoryboard.Begin();
			}
		}
		protected virtual Panel GetCellsPanel() {
			return (Panel)GetTemplateChild(ElementCellsName);
		}
		protected virtual ContentControl GetPreviewPanel() {
			return GetTemplateChild(ElementPreviewName) as ContentControl;
		}
		protected virtual AgDataGridCell CreateCellControl(AgDataGridColumn column) {
			AgDataGridCell cell = new AgDataGridCell(column, Owner, Handle);
			return cell;
		}
		protected internal override void UpdateCellState(AgDataGridCell cell) {
			cell.State = GetCellState(Owner.FocusedColumn == cell.Column, State, Owner.IsEditorShown);
		}
		protected override void OnHandleUpdate() {
			foreach (KeyValuePair<AgDataGridColumn, AgDataGridCell> cell in Cells) {
				cell.Value.RowHandle = Handle;
			}
			TogglePreviewWithNoAnimation();
			base.OnHandleUpdate();
		}
	}
	[TemplatePart(Name = ExpandButtonName, Type = typeof(ButtonBase))]
	public class AgDataGridGroupRow : AgDataGridRowBase {
		const string ExpandButtonName = "ExpandButton";
		const string ExpandedStateName = "Expanded";
		const string CollapsedStateName = "Collapsed";
		public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("ValueProperty", typeof(object), typeof(AgDataGridGroupRow), null);
		public AgDataGridGroupRow(int index, IAgDataGridRowOwner owner, object value)
			: base(index, owner) {
			DefaultStyleKey = typeof(AgDataGridGroupRow);
			SetExpandProperties(IsExpanded, false);
			SetValue(ValueProperty, value);
			this.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(AgDataGridGroupRow_MouseLeftButtonDown);
		}
		void AgDataGridGroupRow_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) {
			if (MouseHelper.IsDoubleClick(e)) {
				ChangeExpandCollapse();
			}
		}
		public object Value { get { return GetValue(ValueProperty); } set { SetValue(ValueProperty, value); } }
		public override AgDataGridRowType RowType { get { return AgDataGridRowType.Group; } }
		protected double RowWidth {
			get {
				return Owner.DataPanelWidth - Margin.Left;
			}
		}
		public override void OnApplyTemplate() {
			base.OnApplyTemplate();
			SetButtonClickHandler(ExpandButtonName);
			SetExpandProperties(IsExpanded, true);
		}
		protected override Size MeasureOverride(Size availableSize) {
			Size res = base.MeasureOverride(new Size(RowWidth, availableSize.Height));
			res.Width = RowWidth;
			return res;
		}
		protected override void SetIndentWidth() {
			Padding = new Thickness(LevelIndent, 0, 0, 0);
		}
		protected internal bool IsExpanded { get { return Owner.IsRowExpanded(Handle); } }
		protected internal void ChangeExpandCollapse() {
			SetExpandProperties(!IsExpanded, false);
			Owner.ChangeExpandState(Handle);
		}
		void SetButtonClickHandler(string name) {
			ButtonBase button = GetTemplateChild(name) as ButtonBase;
			if (button != null) {
				button.Click += new RoutedEventHandler(button_Click);
			}
		}
		void button_Click(object sender, RoutedEventArgs e) {
			ChangeExpandCollapse();
		}
		public virtual FrameworkElement ExpandButton { get { return GetTemplateChild("ExpandButton") as FrameworkElement; } }
		public virtual void SetExpandProperties(bool isExpanded, bool immediately) {
			if (immediately) {
				(ExpandButton.RenderTransform as RotateTransform).Angle = isExpanded ? 90 : 0;
			} else
				VisualStateManager.GoToState(this, isExpanded ? ExpandedStateName : CollapsedStateName, true);
		}
		protected override void OnHandleUpdate() {
			Value = Owner.GetGroupDisplayText(Handle);
			SetExpandProperties(IsExpanded, true);
			base.OnHandleUpdate();
		}
	}
}
